package it.polimi.traveldream.web.beans.employee;

import java.util.List;

import it.polimi.traveldream.ejbclient.dtos.TravelPackageDTO;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class PackageDataModel extends ListDataModel<TravelPackageDTO> implements SelectableDataModel<TravelPackageDTO>{
	
	public PackageDataModel() {  
    }  
  
    public PackageDataModel(List<TravelPackageDTO> data) {  
        super(data);  
    }  
      
    @SuppressWarnings("unchecked")
	@Override  
    public TravelPackageDTO getRowData(String rowKey) {  
        List<TravelPackageDTO> travelPackages = (List<TravelPackageDTO>) getWrappedData();  
          
        for(TravelPackageDTO travelPackage : travelPackages) {  
            if(rowKey.equals(travelPackage.getId())) {
                return travelPackage;  
            }
        }
        
        return null;  
    }  
  
    @Override  
    public String getRowKey(TravelPackageDTO travelPackage) {
        return String.valueOf(travelPackage.getId());  
    }
    
}
